package com.qujia.station.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.qujia.common.core.domain.model.LoginUser;
import com.qujia.common.utils.SecurityUtils;
import com.qujia.common.utils.StringUtils;
import com.qujia.station.domain.TimingPayWay;
import com.qujia.station.service.ITimingPayWayService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qujia.common.annotation.Log;
import com.qujia.common.core.controller.BaseController;
import com.qujia.common.core.domain.AjaxResult;
import com.qujia.common.enums.BusinessType;
import com.qujia.common.utils.poi.ExcelUtil;
import com.qujia.common.core.page.TableDataInfo;

/**
 * 定时修改支付方式Controller
 * 
 * @author qujia
 * @date 2022-12-01
 */
@RestController
@RequestMapping("/Timing/way")
public class TimingPayWayController extends BaseController
{
    @Autowired
    private ITimingPayWayService timingPayWayService;
    private static final Map<String,String> PayTypeMap = new HashMap<>();

    static {

        PayTypeMap.put("1","随行付");
        PayTypeMap.put("2","云闪付");
        PayTypeMap.put("3","通联");
        PayTypeMap.put("4","金控");
    }
    /**
     * 查询定时修改支付方式列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TimingPayWay timingPayWay)
    {
        LoginUser current= SecurityUtils.getLoginUser();
        timingPayWay.setEnterpriseId(current.getUser().getEnterpriseId());
        timingPayWay.setDelFlag("0");
        startPage();
        List<TimingPayWay> list = timingPayWayService.selectTimingPayAllWayList(timingPayWay);
        for(TimingPayWay timingPayWay1:list){
            if(timingPayWay1.getWxPayRemark()==null){
                timingPayWay1.setWxChinese(PayTypeMap.get(timingPayWay1.getWxPayType())+"-");
            }else {
                timingPayWay1.setWxChinese(PayTypeMap.get(timingPayWay1.getWxPayType())+"-"+timingPayWay1.getWxPayRemark());
            }

            if(timingPayWay1.getRechargePayRemark()==null){
                timingPayWay1.setWxRechargeChinese(PayTypeMap.get(timingPayWay1.getRechargePayType())+"-");
            }else {
                timingPayWay1.setWxRechargeChinese(PayTypeMap.get(timingPayWay1.getRechargePayType())+"-"+timingPayWay1.getRechargePayRemark());
            }

            if(timingPayWay1.getZfbPayRemark()==null){
                timingPayWay1.setZfbChinese(PayTypeMap.get(timingPayWay1.getZfbPayType())+"-");
            }else {
                timingPayWay1.setZfbChinese(PayTypeMap.get(timingPayWay1.getZfbPayType())+"-"+timingPayWay1.getZfbPayRemark());;
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出定时修改支付方式列表
     */

    @Log(title = "定时修改支付方式", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TimingPayWay timingPayWay)
    {
        List<TimingPayWay> list = timingPayWayService.selectTimingPayWayList(timingPayWay);
        ExcelUtil<TimingPayWay> util = new ExcelUtil<TimingPayWay>(TimingPayWay.class);
        return util.exportExcel(list, "way");
    }

    /**
     * 获取定时修改支付方式详细信息
     */

    @GetMapping(value = "/{timeId}")
    public AjaxResult getInfo(@PathVariable("timeId") Long timeId)
    {
        return AjaxResult.success(timingPayWayService.selectTimingPayWayById(timeId));
    }

    /**
     * 新增定时修改支付方式
     */

    @Log(title = "定时修改支付方式", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TimingPayWay timingPayWay)
    {
        LoginUser loginUser= SecurityUtils.getLoginUser();
        timingPayWay.setEnterpriseId(loginUser.getUser().getEnterpriseId());
        timingPayWay.setCreateDate(new Date());
        if(timingPayWay.getDaylist()!=null){
            timingPayWay.setDays( StringUtils.join(timingPayWay.getDaylist(),","));
        }
        return toAjax(timingPayWayService.insertTimingPayWay(timingPayWay));
    }

    /**
     * 修改定时修改支付方式
     */

    @Log(title = "定时修改支付方式", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TimingPayWay timingPayWay)
    {
        timingPayWay.setUpdateDate(new Date());
        if(timingPayWay.getDaylist()!=null){
            timingPayWay.setDays( StringUtils.join(timingPayWay.getDaylist(),","));
        }
        return toAjax(timingPayWayService.updateTimingPayWay(timingPayWay));
    }

    /**
     * 删除定时修改支付方式
     */

    @Log(title = "定时修改支付方式", businessType = BusinessType.DELETE)
	@DeleteMapping("/{timeIds}")
    public AjaxResult remove(@PathVariable Long[] timeIds)
    {
        return toAjax(timingPayWayService.deleteTimingPayWayByIds(timeIds));
    }
}
